package tk.mybatis.springboot.spider.pipeline;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import tk.mybatis.springboot.service.SpringerService;
import tk.mybatis.springboot.spider.entity.LiteratureEntity;
import us.codecraft.webmagic.ResultItems;
import us.codecraft.webmagic.Task;
import us.codecraft.webmagic.pipeline.Pipeline;

@Component("errorPipeline")
public class ErrorPipeline implements Pipeline {

    public ErrorPipeline() {

    }

    public ErrorPipeline(SpringerService springerService) {
        this.springerService = springerService;
    }

    @Autowired
    private SpringerService springerService;


    @Override

    public void process(ResultItems resultItems, Task task) {

        LiteratureEntity teLiterature = resultItems.get("literature");
        if (teLiterature != null) {
            if (springerService.save(teLiterature)) {
                System.out.println("errorPipeline==保存成功～");
            }
        }
    }
}
